package physicalObjects;
import simulation.Simulation;


/**
 *
 * @author Michael Elgart
 */
public class Muscle extends Spring {

    private double myAmp;
    private double myRestLength;
    private long myStartTime;
    private int myWavePeriod;

    /**
     * Constructor for this class.
     * @param start Mass on start end of the muscle
     * @param end Mass on end of muscle
     * @param length rest length of the muscle
     * @param kVal k value associated with the spring/muscle
     * @param amp max distance muscle will contract in or out from rest length
     */
    public Muscle(
            Mass start, Mass end, double length, double kVal, double amp) {
        super(start, end, length, kVal);
        myAmp = amp;
        myRestLength = length;
        myStartTime = System.currentTimeMillis();
        //Period of the wave in milliseconds:
        myWavePeriod = 1000;
    }

    /**
     * @param canvas The simulation where this is running
     * @param dt change
     */
    public void update(Simulation canvas, double dt) {
        long currentTime = System.currentTimeMillis() - myStartTime;
        setMyLength(myRestLength
                + myAmp * Math.sin(2 * (Math.PI) / myWavePeriod * currentTime));

        super.update(canvas, dt);
    }
    
    
}
